package com.dap.param;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dap.commons.ApplicationEnum;
import com.dap.commons.PlatformEnum;

import java.io.Serializable;

/**
 * @desc 平台公用报文头信息
 * @author wang min
 */
public class ControlData implements Serializable {
    private static final long serialVersionUID = 5713354867420373586L;


    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("pageSize=").append(pageSize).append(",pageIndex=").append(pageIndex);

        if (cuserId != null)
            sb.append(",cuserId=").append(cuserId);
        if (traderId != null)
            sb.append(",traderId=").append(traderId);

        return sb.toString();
    }

    public ControlData() {}
    public ControlData buildAttributesOnlyFromFrontend() {
        ControlData cd = new ControlData();
        cd.pageSize = this.pageSize;
        cd.pageIndex = this.pageIndex;
        cd.xToken = this.xToken;
        cd.version = this.version;
        cd.frontendVersion = this.frontendVersion;
        return cd;
    }


    /**
     * 从前端获取, 分页参数,本页记录数
     */
    private int pageSize = 10;
    /**
     * 从前端获取, 分页参数,页码,从1开始
     */
    private int pageIndex = 1;
    /**
     * 从前端获取, 一个session, 请求需要做额外验证, 不传不验证
     */
    private String xToken;
    /**
     * 从前端获取, 指定接口的版本
     */
    private String version;
    /**
     * 从前端获取, 指定前端的版本
     */
    private String frontendVersion;


    /**
     * 服务调用方IP
     */
    private String hostIp;
    /**
     * 当前交易的sessionId
     */
    private String sessionId;
    private String clientIp;

    /**
     * 用户ID, b2b为employeeId, b2c为C端的loginId或者userId
     */
    @Deprecated
    private Long userId;
    private Long employeeId;
    /**
     * C端的userId
     */
    private Long cuserId;

    /***
     *
     * 登陆账号
     */
    private String loginName;
    /**
     * 绑定电话
     */
    private String mobile;
    /**
     * 交易主体id
     */
    private Long traderId;

    private Long districtId;

    private Integer erpType;

    @Deprecated
    private String name;
    private String employeeName;
    private String userRealName;

    private Integer isDepartmentLeader;
    private int isAdmin;
    private Long managerId;

    private Integer isHotel;
    private Long hotelSupplierId;


    private String wxOpenId;
    private String wxUnionId;


    private Integer appId;
    private ApplicationEnum applicationEnum;

    // 设备的平台类型
    private String platform;
    private PlatformEnum platformEnum;

    // 内部请求来源, 外部请求, 该属性为空
    private String internalRequestSource;

    /**
     * 使用json格式存放所有的非公共参数
     */
    private String jsonAttributes;



    public <T> T getJsonAttribute(String valueName, Class<T> clazz) {
        JSONObject json = JSON.parseObject(jsonAttributes);
        if (null == json) {
            return null;
        }
        return json.getObject(valueName, clazz);
    }




    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public String getxToken() {
        return xToken;
    }

    public void setxToken(String xToken) {
        this.xToken = xToken;
    }

    public String getHostIp() {
        return hostIp;
    }

    public void setHostIp(String hostIp) {
        this.hostIp = hostIp;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getFrontendVersion() {
        return frontendVersion;
    }

    public void setFrontendVersion(String frontendVersion) {
        this.frontendVersion = frontendVersion;
    }

    public String getClientIp() {
        return clientIp;
    }

    public void setClientIp(String clientIp) {
        this.clientIp = clientIp;
    }

    @Deprecated
    public Long getUserId() {
        return userId;
    }
    @Deprecated
    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Long getEmployeeId() {
        return employeeId;
    }
    public void setEmployeeId(Long employeeId) {
        this.employeeId = employeeId;
    }

    public Long getCuserId() {
        return cuserId;
    }
    public void setCuserId(Long cuserId) {
        this.cuserId = cuserId;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public Long getTraderId() {
        return traderId;
    }

    public void setTraderId(Long traderId) {
        this.traderId = traderId;
    }

    public Long getDistrictId() {
        return districtId;
    }

    public void setDistrictId(Long districtId) {
        this.districtId = districtId;
    }

    public Integer getErpType() {
        return erpType;
    }
    public void setErpType(Integer erpType) {
        this.erpType = erpType;
    }

    @Deprecated
    public String getName() {
        return name;
    }
    @Deprecated
    public void setName(String name) {
        this.name = name;
    }

    public String getEmployeeName() {
        return employeeName;
    }
    public void setEmployeeName(String employeeName) {
        this.employeeName = employeeName;
    }

    public String getUserRealName() {
        return userRealName;
    }
    public void setUserRealName(String userRealName) {
        this.userRealName = userRealName;
    }

    public Integer getIsDepartmentLeader() {
        return isDepartmentLeader;
    }

    public void setIsDepartmentLeader(Integer isDepartmentLeader) {
        this.isDepartmentLeader = isDepartmentLeader;
    }

    public int getIsAdmin() {
        return isAdmin;
    }

    public void setIsAdmin(int isAdmin) {
        this.isAdmin = isAdmin;
    }

    public Long getManagerId() {
        return managerId;
    }

    public void setManagerId(Long managerId) {
        this.managerId = managerId;
    }

    public Integer getIsHotel() {
        return isHotel;
    }

    public void setIsHotel(Integer isHotel) {
        this.isHotel = isHotel;
    }

    public Long getHotelSupplierId() {
        return hotelSupplierId;
    }

    public void setHotelSupplierId(Long hotelSupplierId) {
        this.hotelSupplierId = hotelSupplierId;
    }

    public String getWxOpenId() {
        return wxOpenId;
    }

    public void setWxOpenId(String wxOpenId) {
        this.wxOpenId = wxOpenId;
    }

    public String getWxUnionId() {
        return wxUnionId;
    }

    public void setWxUnionId(String wxUnionId) {
        this.wxUnionId = wxUnionId;
    }

    public Integer getAppId() {
        return appId;
    }

    public void setAppId(Integer appId) {
        this.appId = appId;
    }

    public ApplicationEnum getApplicationEnum() {
        return applicationEnum;
    }

    public void setApplicationEnum(ApplicationEnum applicationEnum) {
        this.applicationEnum = applicationEnum;
    }

    public String getPlatform() {
        return platform;
    }

    public void setPlatform(String platform) {
        this.platform = platform;
    }

    public PlatformEnum getPlatformEnum() {
        return platformEnum;
    }

    public void setPlatformEnum(PlatformEnum platformEnum) {
        this.platformEnum = platformEnum;
    }

    public String getInternalRequestSource() {
        return internalRequestSource;
    }

    public void setInternalRequestSource(String internalRequestSource) {
        this.internalRequestSource = internalRequestSource;
    }

    public String getJsonAttributes() {
        return jsonAttributes;
    }

    public void setJsonAttributes(String jsonAttributes) {
        this.jsonAttributes = jsonAttributes;
    }
}
